package mx.netbrain.action;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import mx.netbrain.business.StorageBusiness;
import mx.netbrain.model.Storage;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class StorageAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer volId;
	private String volNombre;
	private String volRuta;
	private BigDecimal volEspacio;
	private boolean volCompartido;
	private List<Storage> list = new ArrayList<Storage>();

	public String execute() {
		return SUCCESS;
	}

	public String list() {
		list = StorageBusiness.list();
		return SUCCESS;
	}

	public String save() {
		StorageBusiness.save(volId, volNombre, volRuta, volEspacio,
				volCompartido);
		return SUCCESS;
	}

	public String edit() {
		Storage storage = new Storage();
		HttpServletRequest request = (HttpServletRequest) ActionContext
				.getContext().get(ServletActionContext.HTTP_REQUEST);
		storage = StorageBusiness.findById(Integer.parseInt(request
				.getParameter("id")));
		volId = storage.getId();
		volNombre = storage.getName();
		volRuta = storage.getRoute();
		volEspacio = storage.getSpace();
		volCompartido = storage.getShare();
		return SUCCESS;
	}

	public String delete() {
		HttpServletRequest request = (HttpServletRequest) ActionContext
				.getContext().get(ServletActionContext.HTTP_REQUEST);
		StorageBusiness.delete(Integer.parseInt(request.getParameter("id")));
		return SUCCESS;
	}

	public Integer getVolId() {
		return volId;
	}

	public void setVolId(Integer volId) {
		this.volId = volId;
	}

	public String getVolNombre() {
		return volNombre;
	}

	public void setVolNombre(String volNombre) {
		this.volNombre = volNombre;
	}

	public String getVolRuta() {
		return volRuta;
	}

	public void setVolRuta(String volRuta) {
		this.volRuta = volRuta;
	}

	public BigDecimal getVolEspacio() {
		return volEspacio;
	}

	public void setVolEspacio(BigDecimal volEspacio) {
		this.volEspacio = volEspacio;
	}

	public boolean isVolCompartido() {
		return volCompartido;
	}

	public void setVolCompartido(boolean volCompartido) {
		this.volCompartido = volCompartido;
	}

	public List<Storage> getList() {
		return list;
	}

	public void setList(List<Storage> list) {
		this.list = list;
	}

}
